<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('家族婚配管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>家族：</label>
                                <select id="surnameId" name="surnameId">
                                    <option value="0">所有</option>
                                    <option th:each="dict : ${fcanList}" th:text="${dict.name}" th:value="${dict.cId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>家族成员：</label>
                                <select id="memberId" name="memberId">
                                    <option value="0">所有</option>
                                </select>
                            </li>
                            <li>
                                <label>配偶成员：</label>
                                <select id="mateId" name="mateId">
                                    <option value="0">所有</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="family:marry:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="family:marry:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="family:marry:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="family:marry:export" style="display: none;">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('family:marry:edit')}]];
        var removeFlag = [[${@permission.hasPermi('family:marry:remove')}]];
        var prefix = ctx + "family/marry";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "家族婚配管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'mId',
                    title: '编号',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'memberId',
                    title: '家族成员编号',
                    align: 'center'
                },
                {
                    field: 'memFullName',
                    title: '家族成员姓名',
                    align: 'center'
                },
                {
                    field: 'memBirthdayStr',
                    title: '家族成员出生日期',
                    align: 'center'
                },
                {
                    field: 'mateId',
                    title: '配偶编号',
                    align: 'center'
                },
                {
                    field: 'mateFullName',
                    title: '配偶姓名',
                    align: 'center'
                },
                {
                    field: 'mateBirthdayStr',
                    title: '配偶出生日期',
                    align: 'center'
                },
                {
                    field: 'surnameName',
                    title: '所属家族',
                    align: 'center'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: 'center'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.mId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.mId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        //家族列表选择项改变联动其他下拉列表改动
        $("#surnameId").change(function (){
            var surnameIdVal = $("#surnameId").val();
            console.log("列表改变的值：" + surnameIdVal);
            //家族改变不管是否请求是否成功都得清空家族成员列表和配偶成员列表的值
            //家族成员下拉列表
            var memberIdSEL = $("#memberId");
            memberIdSEL.empty();
            memberIdSEL.append("<option value='0'>所有</option>");
            //配偶成员下拉列表
            var mateIdSEL = $("#mateId");
            mateIdSEL.empty();
            mateIdSEL.append("<option value='0'>所有</option>");
            $.ajax({
                url: prefix + "/clanSelectChange",
                type: 'GET',
                data: {
                    surnameId: surnameIdVal
                },
                success: function (data) {
                    if(data.code == 0 && data.rows.length > 0){
                        //联动家族成员下拉列表
                        var memberList = data.rows[0].memberList;
                        if(memberList.length > 0){
                            for (var k = 0; k < memberList.length; k++) {
                                memberIdSEL.append("<option value='" + memberList[k].mId + "'>" + memberList[k].fullName + "（编号：" + memberList[k].mId + "）</option>");
                            }
                        }
                        //联动配偶成员下拉列表
                        var fMateList = data.rows[0].fMateList;
                        if(fMateList.length > 0){
                            for (var j = 0; j < fMateList.length; j++) {
                                mateIdSEL.append("<option value='" + fMateList[j].mId + "'>" + fMateList[j].surname + fMateList[j].name + "（编号：" + fMateList[j].mId + "）</option>");
                            }
                        }
                    }
                }
            });
        });
    </script>
</body>
</html>